<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>课程体系管理</title>
    <meta name="decorator" content="default"/>
    <script type="text/javascript">
        $(document).ready(function () {
            //$("#name").focus();
            $("#inputForm").validate({
                submitHandler: function (form) {
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function (error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
        });
        function checkValidate() {
            var coursesystemName = document.getElementById("coursesystemName").value;
            var courseAttribute = document.getElementById("coursesystemAttribute").value;
            var duallist = document.getElementById("duallist").value;
            //判断是否为空
            if (coursesystemName == "" || coursesystemName == null) {
                window.alertx("请输入课程体系名称！");
                return false;
            }
            if (courseAttribute == "" || courseAttribute == null) {
                window.alertx("请选择课程体系属性！");
                return false;
            }
            if (duallist == "" || duallist == null) {
                window.alertx("请选择课程！");
                return false;
            }
        }
        function CoursesystemAttribute(attribute){
            $.ajax({
                type: "POST",
                url: "${ctx}/resource/resourceCoursesystem/findCourseListByAttribute",
                data: {
                    attribute:attribute.options[attribute.selectedIndex].value
                },
                success:function(json){
                    $(".resetDuallist").empty();
                    var list = json.dataObj;
                    for(var i=0;i<list.length;i++)
                    {
                        $("#duallist").append("<option value='"+ list[i].id+"'>"+list[i].courseName+"</option>");
                    }
                    $(".resetDuallist").bootstrapDualListbox('refresh');
                },
                error:function(){
                    alertx("error");
                }
            });
        }
    </script>

    <script type="text/javascript" src="${path}/js/common/jquery.min.js"></script>
    <link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"
          type="text/css" media="all">
    <%--<link rel="stylesheet" href="${path}/css/common/bootstrap.min.css" rel="stylesheet" type="text/css" media="all"/>--%>
    <link rel="stylesheet" href="${path}/css/common/bootstrap-duallistbox.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="${path}/js/common/jquery.bootstrap-duallistbox.js"></script>

    <style>
        .control-label {
            font-weight: normal;
        }

        #coursesystemName {
            height: 30px;
        }
    </style>
</head>
<body>
<ul class="nav nav-tabs">
    <li><a href="${ctx}/resource/resourceCoursesystem/">课程体系列表</a></li>
    <li class="active"><a
            href="${ctx}/resource/resourceCoursesystem/form?id=${resourceCoursesystem.id}">课程体系<c:choose><c:when
            test="${not empty type}">复制</c:when><c:otherwise><shiro:hasPermission
            name="resource:resourceCoursesystem:edit">${not empty resourceCoursesystem.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission
            name="resource:resourceCoursesystem:edit">查看</shiro:lacksPermission></c:otherwise></c:choose></a></li>
</ul>
<br/>
<form:form id="inputForm" modelAttribute="resourceCoursesystem" action="${ctx}/resource/resourceCoursesystem/save"
           method="post" class="form-horizontal">
    <form:hidden path="id"/>
    <input type="hidden" name="type" id="type" value="${type}">
    <sys:message content="${message}"/>
    <div class="control-group">
        <label class="control-label">课程体系名称：</label>

        <div class="controls">
            <form:input name="coursesystemName" path="coursesystemName" htmlEscape="false" maxlength="64"
                        class="input-xlarge required"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">课程体系属性：</label>

        <div class="controls">
            <select id="coursesystemAttribute" name="coursesystemAttribute" class="input-xlarge required">

                <c:choose>
                    <c:when test="${isSuperAdmin=='false'}">
                        <option value="0" selected>${fns:getDictLabel("0",'resource_coursesystem_attribute',"无")}</option>
                    </c:when>
                    <c:otherwise>
                        <c:forEach var="attribute" items="${fns:getDictList('resource_coursesystem_attribute')}">
                            <option value="${fns:getDictValue(attribute,'resource_coursesystem_attribute',"")}" <c:if test="${fns:getDictValue(attribute,'resource_coursesystem_attribute','')==resourceCoursesystem.coursesystemAttribute}">selected</c:if>>${attribute}</option>
                        </c:forEach>
                    </c:otherwise>
                </c:choose>

            </select>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">选择课程：</label>

        <div class="controls">
            <div class="container"></div>
                <%--<%@ include file="maskProgramFormTest.jsp"%>--%>
            <div class="col-lg-10 col-md-9 col-sm-9 col-xs-12">
                <select multiple="multiple" size="10" id="duallist" name="duallist" class="resetDuallist">
                    <c:forEach var="resourceCourse" items="${resourceCourseList}">
                        <option value="${resourceCourse.id}"
                                <c:if test="${resourceCourse.isChoose=='true'}">selected</c:if>>${resourceCourse.courseName}</option>
                    </c:forEach>
                </select>
            </div>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">备注信息：</label>

        <div class="controls">
            <form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
        </div>
    </div>
    <div class="form-actions">
        <shiro:hasPermission name="resource:resourceCoursesystem:edit"><input id="btnSubmit" class="btn btn-primary"
                                                                              type="submit" value="保 存"
                                                                              onclick=" return checkValidate()"/>&nbsp;</shiro:hasPermission>
        <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
    </div>
</form:form>
<script>
    var demo1 = $('select[class="resetDuallist"]').bootstrapDualListbox();
    $("#demoform").submit(function () {
        alert($('[class="resetDuallist"]').val());
        return false;
    });
</script>
</body>
</html>